package com.cms.edm.service.impl;

import com.cms.edm.entity.TemplateEntity;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cms.common.utils.PageUtils;
import com.cms.common.utils.Query;

import com.cms.edm.dao.TeacherDao;
import com.cms.edm.entity.TeacherEntity;
import com.cms.edm.service.TeacherService;


@Service("teacherService")
public class TeacherServiceImpl extends ServiceImpl<TeacherDao, TeacherEntity> implements TeacherService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        String key = (String) params.get("key");
        QueryWrapper<TeacherEntity> wrapper = new QueryWrapper<>();
        if(!StringUtils.isEmpty(key)){
            wrapper.eq("code", key).or().like("name", key);
        }
        IPage<TeacherEntity> page = this.page(
                new Query<TeacherEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

    @Override
    public TeacherEntity login(TeacherEntity teacher) {
        QueryWrapper<TeacherEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("code", teacher.getCode()).eq("password", teacher.getPassword());
        TeacherEntity teacherEntity = baseMapper.selectOne(wrapper);
        return teacherEntity;
    }

    @Override
    public TeacherEntity validPwd(TeacherEntity teacher) {
        QueryWrapper<TeacherEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("id", teacher.getId()).eq("password", teacher.getPassword());
        TeacherEntity teacherEntity = baseMapper.selectOne(wrapper);
        return teacherEntity;
    }

}